home *** CD-ROM | disk | FTP | other *** search
- unit UMemX;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- E_MemMap, Buttons, StdCtrls, Mask, ComCtrls;
-
- type
- TForm1 = class(TForm)
- SpeedButton1: TSpeedButton;
- SpeedButton2: TSpeedButton;
- Label1: TLabel;
- NdxEdit: TMaskEdit;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure SpeedButton1Click(Sender: TObject);
- procedure SpeedButton2Click(Sender: TObject);
- private
- { Private declarations }
- EMemMap : TEMemMap;
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
- Const
- MaxArrSize = 16384;
- Type
- IntArr = Array[0..MaxArrSize-1] Of Integer;
- IntArrPtr = ^IntArr;
-
- procedure TForm1.FormCreate(Sender: TObject);
- Var
- I : Integer;
- IArr : IntArrPtr;
- begin
- Caption:='Int Array [0..'+IntToStr(MaxArrSize-1)+']';
- EMemMap:=TEMemMap.Create(Self);
- EMemMap.CreateMutex('DAVESMUTEX1');
- If NOT EMemMap.MapExisting('DAVESMAP1',SizeOf(IntArr)) then
- begin
- New(IArr);
- For I:=0 To MaxArrSize-1 do
- IArr^[I]:=I+1;
- Try
- If NOT EMemMap.CreateMemMap('DAVESMAP1',SizeOf(IntArr),IArr^) then
- EMemMap.RaiseMappingException;
- Finally
- Dispose(IArr);
- end;
- end;
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- EMemMap.Free;
- end;
- procedure TForm1.SpeedButton1Click(Sender: TObject);
- Var
- AnInt : Integer;
- begin
- AnInt:=StrToInt(NdxEdit.Text);
- If (AnInt>=0) AND (AnInt<MaxArrSize) then
- begin
- EMemMap.EnterCriticalSection;
- Try
- AnInt:=IntArrPtr(EMemMap.MemMap)^[AnInt];
- Finally
- EMemMap.LeaveCriticalSection;
- end;
- MessageDlg(IntToStr(AnInt),mtInformation,[mbOk],0);
- end;
- end;
-
- procedure TForm1.SpeedButton2Click(Sender: TObject);
- Var
- Ndx : Integer;
- AnInt : Integer;
- AValue : String;
- begin
- Ndx:=StrToInt(NdxEdit.Text);
- If (Ndx>=0) AND (Ndx<MaxArrSize) then
- begin
- EMemMap.EnterCriticalSection;
- Try
- AnInt:=IntArrPtr(EMemMap.MemMap)^[Ndx];
- AValue:=IntToStr(AnInt);
- InputQuery('Get Value','NewValue',AValue);
- AnInt:=StrToInt(AValue);
- IntArrPtr(EMemMap.MemMap)^[Ndx]:=AnInt;
- Finally
- EMemMap.LeaveCriticalSection;
- end;
- end;
- end;
-
-
- end.
-